package cn.sypt.yuhao.model;

import java.io.IOException;

import javax.mail.MessagingException;
import javax.mail.Session;

import cn.itcast.mail.Mail;
import cn.itcast.mail.MailUtils;

public class JavaMail {

	public void send(String to, String subject, String content) {
		String host = "smtp.163.com";//服务器主机名
		String name = "experimentlearning@163.com";//登录名
		String pass = "learning2016";//登录密码
		Session session = MailUtils.createSession(host, name, pass);
		
		/*
		 * 创建Mail对象
		 */
		String from = "experimentlearning@163.com";
		
		Mail mail = new Mail(from, to, subject, content);
		/*
		 * 发送邮件
		 */
		try {
			MailUtils.send(session, mail);
		} catch (MessagingException e) {
			throw new RuntimeException(e);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		
		
	}

}
